// index.js
// 获取应用实例
import {
  post,
  get
} from '../../utils/request'
import {
  APIS
} from '../../utils/api'
import {timestampToTime} from '../../utils/util'
const app = getApp();

Page({
  data: {
    isShowTip: true,
    orderId: '',
    orderInfo: {},
    userInfo: {}
  },
  async onLoad(options) {
    const userInfo = wx.getStorageSync('userInfo');
    const {orderId} = options;
    this.setData({
      orderId,
      userInfo
    });
    this.getOrderInfo(orderId);
  },
  getOrderInfo(orderId) {
    get(`${APIS.order}/${orderId}`).then(res => {
      const info = res.data;
      this.setData({
        orderInfo: {
          ...info,
          start: timestampToTime(Number(info.start), 1),
          end: timestampToTime(Number(info.end), 1)
        }
      });
    });
  },
  handleToPay() {
    wx.navigateTo({
      url: '/subPackage/pages/pay'
    })
  },
  handleToHome() {
    wx.switchTab({
      url: '/pages/index/index'
    })
  },
  handleShowTip() {
    this.setData({
      isShowTip: true
    });
  },
  closePop() {
    this.setData({
      isShowTip: false
    });
  },
  onShareAppMessage() {
    return getApp().globalData.shareMessage
  }
})